import 'package:flutter/material.dart';
import 'package:s_mankey/config/resource_mananger.dart' show IconFonts;
import 'package:s_mankey/config/resource_mananger.dart';
import 'package:s_mankey/generated/I18n.dart';
import 'package:s_mankey/ui/page/enterprise_page.dart';
import 'package:s_mankey/ui/page/home_page.dart';
import 'package:s_mankey/ui/page/loginWidget/login_page.dart';
import 'package:s_mankey/ui/page/more_page.dart';
import 'package:s_mankey/ui/page/user_page.dart';

import 'EnterpriseWidget/enterprise_detail.dart';


List<Widget> _pages = [
  HomePage(),
//  EnterpriseDetail(),
  EnterprisePage(),
//  MyPage(),
  UserPage(),
//  MoreSetting(),
//  ShowDialogDemo(),
  MorePage(),
//LoginPage(),
//  ScanPage(),
//  MoreSetting(authorityChanged: (int value){
//    //是不是可以从这里考虑更新showDialog的视图?
//    return print('选返了第$value个tap');
//
//  },),
//  OriginAuthority(),
];

class TabNav extends StatefulWidget {
  @override
  _TabNav createState() => _TabNav();
}

class _TabNav extends State<TabNav> {
  /// 当前控制器索引。
  int _currentIndex = 0;

  /// 创建一个控制器。
  var _pageController = PageController();

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      body: PageView.builder(
        physics: NeverScrollableScrollPhysics(),
        itemBuilder: (BuildContext context, int index) => _pages[index], //index的值传给_currentIndex，再由currentIndex重绘视图视图。
        itemCount: _pages.length,
        controller: _pageController,
        onPageChanged: (index){
          setState(() {
            _currentIndex = index;
          });
        },
      ),
      bottomNavigationBar: BottomNavigationBar(
          elevation: 0,
          type: BottomNavigationBarType.fixed,
          selectedItemColor: AppColor.btnNavBarIconColor,
          currentIndex: _currentIndex,
          onTap: (int index) {
            _pageController.jumpToPage(index); //点击跳转页面的值会传给itemBuilder的index
          },
          items: [
            _seBtmNavBarItem(iconCode: 0xe658, title: I18n.current.discovery),
//            _seBtmNavBarItem(iconCode: 0xe66f, title: I18n.current.circle),
            _seBtmNavBarItem(iconCode: 0xe679, title: I18n.current.enterpriseService),
            _seBtmNavBarItem(iconCode: 0xe657, title: I18n.current.me),
            _seBtmNavBarItem(iconCode: 0xe676, title: I18n.current.more),
          ]),
    );
  }
}

///快速生成BtnTabBarIcon
_seBtmNavBarItem({int iconCode, String title, double size = AppCustomSize.IconDataSize}) {
  return BottomNavigationBarItem(
      icon: Icon(
        IconData(iconCode, fontFamily: IconFonts.fontFamily),
        size: size,
      ),
      title: Text(title));
}
